package com.movitech.mobile.cz.base.purchase.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.purchase.bizvo.DealRequestVO;
import com.movitech.mobile.cz.base.purchase.bizvo.PSpPlanConfirmProcReqvo;
import com.movitech.mobile.cz.base.purchase.entity.PSpPlanConfirmProc;
import com.movitech.mobile.cz.base.purchase.service.PSpPlanConfirmProcService;
import com.movitech.mobile.cz.base.supplier.bizvo.PurchasePlanConfirmHistoryRequestVO;
import com.movitech.mobile.cz.base.supplier.entity.ext.ExtSHistoryComment;
import com.movitech.mobile.cz.base.supplier.service.SHistoryCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * PSpPlanConfirmProc 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-08
 */
@RestController
@RequestMapping("/v1/pSpPlanConfirmProc")
@Api(value = "专项采购计划-专项采购计划确认基础操作接口", description = "专项采购计划-专项采购计划确认基础操作接口")
public class PSpPlanConfirmProcController {
    @Autowired
    private PSpPlanConfirmProcService pSpPlanConfirmProcService;

    @Autowired
    private SHistoryCommentService sHistoryCommentService;
    
    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有专项采购计划-专项采购计划确认接口",
            notes = "获取所有专项采购计划-专项采购计划确认接口",
            response = PSpPlanConfirmProc.class
    )
    public RestReturnResult list() {
        RestReturnResult restResult = RestReturnResult.success();
        Page<PSpPlanConfirmProc> page = pSpPlanConfirmProcService.selectPage(new Page<PSpPlanConfirmProc>());
        restResult.setData(page);
        return restResult;
    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "专项采购计划-专项采购计划确认列表查询接口",
            notes = "专项采购计划-专项采购计划确认列表查询接口",
            response = PSpPlanConfirmProc.class
    )
    public RestReturnResult searchList(@RequestBody PSpPlanConfirmProc pSpPlanConfirmProc,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
        RestReturnResult restResult = RestReturnResult.success();
        Page<PSpPlanConfirmProc> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(pSpPlanConfirmProc);
        page = pSpPlanConfirmProcService.selectPage(page,wrapper);
        restResult.setData(page);
        return restResult;
    }

    @GetMapping("/getPSpPlanConfirmProc/{id}")
    @ApiOperation(
            value = "专项采购计划-专项采购计划确认对象ID获取接口",
            notes = "专项采购计划-专项采购计划确认对对象ID获取接口",
            response = PSpPlanConfirmProc.class
    )
    public RestReturnResult addPSpPlanConfirmProc(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        PSpPlanConfirmProc pSpPlanConfirmProc = pSpPlanConfirmProcService.selectById(id);
        restResult.setData(pSpPlanConfirmProc);
        return restResult;
    }
    

    @PostMapping("/add")
    @ApiOperation(
            value = "专项采购计划-专项采购计划确认添加接口",
            notes = "专项采购计划-专项采购计划确认添加接口",
            response = PSpPlanConfirmProc.class
    )
    public RestReturnResult add(@RequestBody PSpPlanConfirmProcReqvo pSpPlanConfirmProcReqvo) {
        RestReturnResult result = RestReturnResult.success();
        pSpPlanConfirmProcService.buildPSpPlanConfirmProc(pSpPlanConfirmProcReqvo);
        return result;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "专项采购计划-专项采购计划确认更新接口",
            notes = "专项采购计划-专项采购计划确认更新接口",
            response = PSpPlanConfirmProc.class
    )
    public RestReturnResult update(@RequestBody PSpPlanConfirmProc pSpPlanConfirmProc) {
        RestReturnResult restResult = RestReturnResult.success();
        pSpPlanConfirmProcService.updateById(pSpPlanConfirmProc);
        restResult.setData(pSpPlanConfirmProc);
        return restResult;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(
            value = "专项采购计划-专项采购计划确认通过ID删除接口",
            notes = "专项采购计划-专项采购计划确认通过ID删除接口",
            response = PSpPlanConfirmProc.class
    )
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        pSpPlanConfirmProcService.deleteById(id);
        return restResult;
    }
    
    @PostMapping("/confirm")
    @ApiOperation(
            value = "专项采购计划-专项采购计划代办确认接口",
            notes = "专项采购计划-专项采购计划代办确认接口",
            response = PSpPlanConfirmProc.class
    )
    public RestReturnResult confirm(@RequestBody DealRequestVO vo) {
        RestReturnResult restResult = RestReturnResult.success();
        pSpPlanConfirmProcService.confirmPSpPlan(vo);
        return restResult;
    }
    
    @PostMapping("/searchConfirmHistoryList")
    @ApiOperation(
            value = "专项采购计划-专项采购计划确认历史列表查询接口",
            notes = "专项采购计划-专项采购计划确认历史列表查询接口",
            response = PSpPlanConfirmProc.class
    )
    public RestReturnResult searchConfirmHistoryList(
    		@RequestBody PurchasePlanConfirmHistoryRequestVO purchasePlanConfirmHistoryRequestVO) {
        RestReturnResult restResult = RestReturnResult.success();
        Page<ExtSHistoryComment> page = new Page<ExtSHistoryComment>();
        page.setCurrent(purchasePlanConfirmHistoryRequestVO.getPageNumber());
        page.setSize(purchasePlanConfirmHistoryRequestVO.getPageSize());
        page = sHistoryCommentService.findConfirmHistory(page,purchasePlanConfirmHistoryRequestVO);
        restResult.setData(page);
        return restResult;
    }

}

